#include <vector>
#include <QOpenGLWidget>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLExtraFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLWidget>
#include <QTimer>
#include <QWidget>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QOpenGLTexture>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <iostream>
#include <QElapsedTimer>

class OpenglWidget :public QOpenGLWidget, QOpenGLFunctions_3_3_Core
{
	Q_OBJECT
public:
	explicit OpenglWidget(QWidget* parent = nullptr);
	~OpenglWidget();
	void update_texture(const QImage& image);

protected:
	void initializeGL() override;
	void resizeGL(int w, int h) override;
	void paintGL() override;

private:
	void setup_shaders();
	void setup_geometry();
	void setup_geometry(const std::string& path);
	void setup_matrices();
	void setup_texture();

public slots:
	void update_model();

private:
	QOpenGLShaderProgram* shader_program;
	unsigned int VAO, VBO, EBO;

	std::vector<float> vertices;
	std::vector<unsigned int> indices;

	QOpenGLTexture* texture_wall;
	QMatrix4x4 modelMatrix;
	QMatrix4x4 viewMatrix;
	QMatrix4x4 projectionMatrix;

	QElapsedTimer m_time;
	QTimer* timer_update;
};